from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-05-03 14:08:11.785953
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 03, May, 2021
Time: 14:08:16
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.9652
Nobs: 280.000 HQIC: -48.6650
Log likelihood: 3392.97 FPE: 4.58860e-22
AIC: -49.1336 Det(Omega_mle): 3.34596e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.419573 0.119610 3.508 0.000
L1.Burgenland 0.067989 0.059646 1.140 0.254
L1.Kärnten -0.224282 0.052990 -4.233 0.000
L1.Niederösterreich 0.102833 0.128165 0.802 0.422
L1.Oberösterreich 0.226925 0.123892 1.832 0.067
L1.Salzburg 0.273324 0.068352 3.999 0.000
L1.Steiermark 0.108184 0.086911 1.245 0.213
L1.Tirol 0.120143 0.060285 1.993 0.046
L1.Vorarlberg -0.033027 0.055258 -0.598 0.550
L1.Wien -0.052739 0.111213 -0.474 0.635
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.439500 0.137990 3.185 0.001
L1.Burgenland 0.004822 0.068812 0.070 0.944
L1.Kärnten 0.329839 0.061133 5.395 0.000
L1.Niederösterreich 0.111140 0.147861 0.752 0.452
L1.Oberösterreich -0.065572 0.142930 -0.459 0.646
L1.Salzburg 0.221731 0.078856 2.812 0.005
L1.Steiermark 0.091712 0.100267 0.915 0.360
L1.Tirol 0.136450 0.069549 1.962 0.050
L1.Vorarlberg 0.151633 0.063750 2.379 0.017
L1.Wien -0.411756 0.128304 -3.209 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.267196 0.060500 4.416 0.000
L1.Burgenland 0.102241 0.030170 3.389 0.001
L1.Kärnten -0.013533 0.026803 -0.505 0.614
L1.Niederösterreich 0.086602 0.064828 1.336 0.182
L1.Oberösterreich 0.286327 0.062666 4.569 0.000
L1.Salzburg 0.017139 0.034573 0.496 0.620
L1.Steiermark -0.000785 0.043961 -0.018 0.986
L1.Tirol 0.068973 0.030493 2.262 0.024
L1.Vorarlberg 0.075112 0.027950 2.687 0.007
L1.Wien 0.113066 0.056253 2.010 0.044
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.209369 0.057982 3.611 0.000
L1.Burgenland 0.027991 0.028914 0.968 0.333
L1.Kärnten 0.009164 0.025687 0.357 0.721
L1.Niederösterreich 0.055475 0.062129 0.893 0.372
L1.Oberösterreich 0.395195 0.060057 6.580 0.000
L1.Salzburg 0.080773 0.033134 2.438 0.015
L1.Steiermark 0.132767 0.042131 3.151 0.002
L1.Tirol 0.050249 0.029223 1.719 0.086
L1.Vorarlberg 0.081235 0.026787 3.033 0.002
L1.Wien -0.042908 0.053911 -0.796 0.426
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.473074 0.113395 4.172 0.000
L1.Burgenland 0.098013 0.056547 1.733 0.083
L1.Kärnten 0.009578 0.050236 0.191 0.849
L1.Niederösterreich 0.014966 0.121506 0.123 0.902
L1.Oberösterreich 0.124098 0.117454 1.057 0.291
L1.Salzburg 0.053960 0.064800 0.833 0.405
L1.Steiermark 0.067690 0.082395 0.822 0.411
L1.Tirol 0.203783 0.057152 3.566 0.000
L1.Vorarlberg 0.034937 0.052387 0.667 0.505
L1.Wien -0.073711 0.105435 -0.699 0.484
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.211739 0.089562 2.364 0.018
L1.Burgenland -0.012653 0.044662 -0.283 0.777
L1.Kärnten -0.006388 0.039678 -0.161 0.872
L1.Niederösterreich -0.012825 0.095969 -0.134 0.894
L1.Oberösterreich 0.416762 0.092769 4.492 0.000
L1.Salzburg 0.013844 0.051181 0.270 0.787
L1.Steiermark -0.027472 0.065078 -0.422 0.673
L1.Tirol 0.161572 0.045140 3.579 0.000
L1.Vorarlberg 0.057756 0.041377 1.396 0.163
L1.Wien 0.203375 0.083275 2.442 0.015
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.219031 0.108580 2.017 0.044
L1.Burgenland 0.020572 0.054146 0.380 0.704
L1.Kärnten -0.071365 0.048103 -1.484 0.138
L1.Niederösterreich -0.060610 0.116347 -0.521 0.602
L1.Oberösterreich 0.019453 0.112467 0.173 0.863
L1.Salzburg 0.082896 0.062049 1.336 0.182
L1.Steiermark 0.323763 0.078896 4.104 0.000
L1.Tirol 0.460989 0.054726 8.424 0.000
L1.Vorarlberg 0.145592 0.050163 2.902 0.004
L1.Wien -0.137298 0.100958 -1.360 0.174
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.205754 0.129881 1.584 0.113
L1.Burgenland 0.042150 0.064768 0.651 0.515
L1.Kärnten -0.074090 0.057540 -1.288 0.198
L1.Niederösterreich 0.113626 0.139172 0.816 0.414
L1.Oberösterreich 0.015913 0.134531 0.118 0.906
L1.Salzburg 0.192128 0.074222 2.589 0.010
L1.Steiermark 0.131273 0.094374 1.391 0.164
L1.Tirol 0.055023 0.065462 0.841 0.401
L1.Vorarlberg 0.106744 0.060003 1.779 0.075
L1.Wien 0.219419 0.120764 1.817 0.069
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.533796 0.071804 7.434 0.000
L1.Burgenland -0.016589 0.035807 -0.463 0.643
L1.Kärnten -0.016459 0.031811 -0.517 0.605
L1.Niederösterreich 0.099967 0.076940 1.299 0.194
L1.Oberösterreich 0.308075 0.074375 4.142 0.000
L1.Salzburg 0.016775 0.041033 0.409 0.683
L1.Steiermark -0.045598 0.052174 -0.874 0.382
L1.Tirol 0.081077 0.036190 2.240 0.025
L1.Vorarlberg 0.102519 0.033173 3.090 0.002
L1.Wien -0.059665 0.066764 -0.894 0.371
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.159687 0.090493 0.166656 0.218046 0.078492 0.085500 0.000847 0.161770
Kärnten 0.159687 1.000000 0.054378 0.212601 0.186116 -0.065644 0.176285 0.020641 0.304645
Niederösterreich 0.090493 0.054378 1.000000 0.246378 0.088891 0.320615 0.145995 0.023632 0.312476
Oberösterreich 0.166656 0.212601 0.246378 1.000000 0.303529 0.259621 0.102110 0.061191 0.140532
Salzburg 0.218046 0.186116 0.088891 0.303529 1.000000 0.150216 0.063368 0.090607 0.017217
Steiermark 0.078492 -0.065644 0.320615 0.259621 0.150216 1.000000 0.095745 0.101136 -0.100376
Tirol 0.085500 0.176285 0.145995 0.102110 0.063368 0.095745 1.000000 0.151652 0.155436
Vorarlberg 0.000847 0.020641 0.023632 0.061191 0.090607 0.101136 0.151652 1.000000 -0.011779
Wien 0.161770 0.304645 0.312476 0.140532 0.017217 -0.100376 0.155436 -0.011779 1.000000